# author: dcc  题目纠错、题目搜索、意见反馈

import requests
from utils.common_dcc import response_time, headerAdmin
from utils.environments_json import urlHead


# /topicapi/reportErrorType/front/list（题目纠错类型列表）
def error_type_list(uri: str, body: dict, session):
    url = urlHead+uri
    res = session.get(url=url, params=body)
    response_time(url=url, res=res)
    return res


# /topicapi/reportErrorType/add（管理后台添加报错类型）
def add_error_type(uri: str, body: dict):
    url = urlHead+uri
    res = requests.post(url=url, json=body, headers=headerAdmin)
    response_time(url=url, res=res)
    return res


# /topicapi/reportError/front/add（纠错提交，type：1.客观题 2.主观题 3.速记本）
def commit_error(uri: str, body: dict, topic_type: int, topic_id: int, error_type_id: int, session):
    url = urlHead+uri
    body["type"] = topic_type
    body["topicId"] = topic_id
    body["errorTypeId"] = error_type_id
    res = session.post(url=url, json=body)
    response_time(url=url, res=res)
    return res


# /topicapi/reportError/search（管理后台，未处理纠错筛选。status： 1.未处理 2.错误已处理 3.无错误；type： 1.客观题 2.主观题 3.速记本 4.速刷题）
def error_search(uri: str, body: dict, status: int, topic_type: int, page_num: int):
    url = urlHead+uri
    body["status"] = status
    body["type"] = topic_type
    body["pageNum"] = page_num
    res = requests.post(url=url, json=body, headers=headerAdmin)
    response_time(url=url, res=res)
    return res


# /topicapi/reportError/updateStatus（管理后台，处理纠错为错误已处理）
def deal_error(uri: str, body: dict, error_id: int, user_id: int, operate_id: int):
    url = urlHead+uri
    body["id"] = error_id
    body["userId"] = user_id
    body["operateId"] = operate_id
    res = requests.post(url=url, json=body, headers=headerAdmin)
    response_time(url=url, res=res)
    return res


# /commonapi/stationLetterRecord/front/page（站内信系统消息列表）
def letter_list(uri: str, body: dict, session):
    url = urlHead+uri
    res = session.post(url=url, json=body)
    response_time(url=url, res=res)
    return res


# /topicapi/topicSearch/front/searchOtopic(searchStopic)（题目搜索，主/客观仅传入不同uri）
def search_topic(uri: str, body: dict, content: str, session):
    url = urlHead+uri
    body["content"] = content
    res = session.post(url=url, json=body)
    response_time(url=url, res=res)
    return res


# /topicapi/chapterPractice/front/continuePractice（搜索结果获取作答，使用的继续练习接口）
def continue_practice(uri: str, otopic_id: int, session):
    url = urlHead+uri
    body = {"otopicIds": otopic_id}
    res = session.get(url=url, params=body)
    response_time(url=url, res=res)
    return res


# /topicapi/topicSearch/front/submit（题目搜索交卷）
def search_submit(uri: str, body: dict, otopic_list: list, session):
    url = urlHead+uri
    body["otopicList"] = otopic_list
    res = session.post(url=url, json=body)
    response_time(url=url, res=res)
    return res


# /commonapi/cmsFeedbackTypeConfig/front/list（意见反馈可用类型列表）
def feedback_type_list(uri: str, body: dict, session):
    url = urlHead+uri
    res = session.get(url=url, params=body)
    response_time(url=url, res=res)
    return res


# /commonapi/cmsFeedbackTypeConfig/add（意见反馈类型添加）
def feedback_type_add(uri: str, body: dict, session):
    url = urlHead+uri
    res = session.post(url=url, json=body)
    response_time(url=url, res=res)
    return res


# /commonapi/cmsFeedbackRecord/front/submit（意见反馈提交）
def feedback_submit(uri: str, body: dict, type_config_id: int, session):
    url = urlHead+uri
    body["typeConfigId"] = type_config_id
    res = session.post(url=url, json=body)
    response_time(url=url, res=res)
    return res


# /commonapi/cmsFeedbackRecord/front/page（我的反馈，列表）
def feedback_record(uri: str, body: dict, session):
    url = urlHead + uri
    res = session.post(url=url, json=body)
    response_time(url=url, res=res)
    return res


# /commonapi/cmsFeedbackRecord/search（管理后台，类型下反馈搜索）
def feedback_search(uri: str, body: dict, page_num: int, type_config_id: int):
    url = urlHead+uri
    body["pageNum"] = page_num
    body["typeConfigId"] = type_config_id
    res = requests.post(url=url, json=body, headers=headerAdmin)
    response_time(url=url, res=res)
    return res


# /commonapi/cmsFeedbackRecord/detail（获取反馈详情）
def feedback_detail(uri: str, feedback_id: int):
    url = urlHead+uri
    body = {"id": feedback_id}
    res = requests.get(url=url, params=body, headers=headerAdmin)
    response_time(url=url, res=res)
    return res


# /commonapi/cmsFeedbackRecord/operate（管理后台，处理意见反馈）
def feedback_deal(uri: str, body: dict, feedback_id: int, user_id: int, type_content: str, operator_id: int, status: int):
    url = urlHead+uri
    body["id"] = feedback_id
    body["userId"] = user_id
    body["typeConfigContent"] = type_content
    body["operatorId"] = operator_id
    body["status"] = status
    res = requests.post(url=url, json=body, headers=headerAdmin)
    response_time(url=url, res=res)
    return res
